using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess;
using Entity; 
namespace Business
{
    public class bStores
    {
        public static int insertStores(eStores store)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@StoreName", SqlDbType.NVarChar);
            pr.Value = store.StoreName;
            paramList.Add(pr);

            pr = new SqlParameter("@StoreAddress", SqlDbType.NVarChar);
            pr.Value = store.StoreAddress ;
            paramList.Add(pr);

            pr = new SqlParameter("@StorePhone", SqlDbType.NVarChar);
            pr.Value = store.StorePhone;
            paramList.Add(pr);

            new SqlParameter("CityID", SqlDbType.Int);
            pr.Value = store.CityID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("insertStores", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }
        public static int updateStores(eStores store)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@StoreID", SqlDbType.Int);
            pr.Value = store.StoreID;
            paramList.Add(pr);

            pr = new SqlParameter("@StoreName", SqlDbType.NVarChar);
            pr.Value = store.StoreName;
            paramList.Add(pr);

            pr = new SqlParameter("@StoreAddress", SqlDbType.NVarChar);
            pr.Value = store.StoreAddress;
            paramList.Add(pr);

            pr = new SqlParameter("@StorePhone", SqlDbType.NVarChar);
            pr.Value = store.StorePhone;
            paramList.Add(pr);

            new SqlParameter("CityID", SqlDbType.Int);
            pr.Value = store.CityID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("updateStores", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static int deleteStores(int storeID)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@StoreID", SqlDbType.Int);
            pr.Value = storeID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("deleteStores", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static DataTable getAllStores()
        {
            DBHelper dbh = new DBHelper();
            DataTable dt = dbh.ExecuteQueryDataTable("getAllStores", CommandType.StoredProcedure, new List<SqlParameter>());
            dbh.CloseConnection();
            return dt;
        }

        public static eStores getStoresByID(int storeID)
        {
            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@StoreID", SqlDbType.Int);
            pr.Value = storeID;
            paramList.Add(pr);

            IList il = bBase.LoadQueryString(typeof(eStores), "getStoresByID", CommandType.StoredProcedure, paramList);
            if (il.Count > 0)
            {
                return (eStores)il[0];
            }
            else
            {
                return null;
            }
        }
    }
}
